package com.utils;

import com.enums.ErrorCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @description 服务异常
 * @author firr
 * @date 2022/12/24 11:08
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ServiceException extends RuntimeException{

    private Integer code;

    private String msg;

    /**
     * 通过异常枚举构建
     * @author firr
     * @date 2022/12/24 11:14
     * @param errorCodeEnum 异常枚举常量
     * @return support.common.exception.ServiceException
     */
    public static ServiceException buildByErrorEnum(ErrorCodeEnum errorCodeEnum) {
        return new ServiceException(errorCodeEnum.getCode(), errorCodeEnum.getMessage());
    }

    /**
     * 通过code和msg构建
     * @author firr
     * @date 2022/12/24 11:14
     * @param code code
     * @param msg msg
     * @return support.common.exception.ServiceException
     */
    public static ServiceException of(Integer code, String msg) {
        return new ServiceException(code, msg);
    }

    public ServiceException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

}
